home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
226_01
/
workup4.c
< prev
Wrap
Text File
|
1987-12-05
|
16KB
|
468 lines
/* HEADER:CUG 226;
TITLE:"ART-CEE";
VERSION:1.4;
DESCRIPTION:"Small artificial intelligence inference engine.
ART-CEE is a rule-based general purpose driver capable of working
with heirarchical and/or propositional information.";
KEYWORDS:artificial intelligence, inference engines, database;
SYSTEM:MS-DOS;
FILENAME:WORKUP4.C;
SEE-ALSO:WORKUP0.C, WORKUP2.C, WORKUP3.C, MANUAL.TXT, WORKUP0.H,
WORKUP1.H, HELP1.AIH, HELP2.AIH, HELP3.AIH, HELP4.AIH, ART-CEE.COM;
AUTHOR:Dan Cheatham;
COMPILER:MIX-C;
*/
/* art-cee artificial intelligence inference engine */
/* */
/* file: workup1.C -- external data definitions */
/* main function */
/* initial input and parse */
/* help */
/* */
#include "stdio"
#include "workup0.h"
float dfwd, drev, ff1, ft[MAX][MAX];
char indff[80], subjs[MAX][77], currfile[32], menu_sw,
oride_sw, filebuf[81];
int x1, x2, filestat, srchdpth, assumpno;
main()
{ wakeup(); menu_sw = 'Y'; oride_sw = 'Y'; assumpno = 0;
x1 = 50; filestat = 0; dfwd = 100.0 ; drev = 0.0; srchdpth = 3;
strcpy(currfile,"ART-CEE.DAT");
while (toupper(indff[0]) != 'X')
{ mainin();
if (x1 > 2 && x2 != 0)
exec_string();
else
{ if (x1 == 1)
commands();
else
{ printf("\nInvalid entry.");
marktime(); } } }
printf("\nSave database (Y/N)? ");
gets(indff);
if (toupper(indff[0]) == 'Y')
savedata(0,MAX);
}
marktime()
{ char xx; printf("\nPress return to proceed."); xx = getchar(); }
wakeup()
{ system("cls");
printf("\n AAAAAA RRRRRRRR TTTTTTTT CCCCCCCC EEEEEEEE EEEEEEEE");
printf("\n AA AA RR RR TT CC EE EE");
printf("\n AA AA RR RR TT CC EE EE");
printf("\n AAAAAAAA RRRRRRRR TT ++++ CC EEEEEE EEEEEE");
printf("\n AA AA RR RR TT ++++ CC EE EE");
printf("\n AA AA RR RR TT CC EE EE");
printf("\n AA AA RR RR TT CCCCCCCC EEEEEEEE EEEEEEEE\n\n");
printf("\n By Dan Cheatham\n\n\n\n\n\n\n");
initialize();
}
showmenu()
{ system("cls");
printf("COMMANDS: SETTABLE DEFAULTS:\n");
printf(" B batch group L load Forward %f\n",dfwd);
printf(" C change subject P print Reverse %f\n",drev);
printf(" D drop rule S save Assumptions %d\n",assumpno);
printf(" G manual group T think thinK depth %d\n",srchdpth);
printf(" H help V view allow Override %c\n",oride_sw);
printf(" I initialize X exit show Menu %c\n",menu_sw);
printf("RULES:\n");
printf(" IF <subject> THEN <predicate>\n");
printf("QUERIES:\n");
printf(" WHO <subject> <?>\n");
printf(" WHAT <subject> <?>\n");
printf(" DESCRIBE <subject>\n");
printf(" IF <subject> THEN <predicate> ?\n\n");
}
commands()
{ switch(toupper(indff[0]))
{ case 'A': setassump() ; break;
case 'B': filegroup() ; break;
case 'C': chgsubj() ; break;
case 'D': droprule() ; break;
case 'F': setfwd() ; break;
case 'G': manugroup() ; break;
case 'H': help() ; break;
case 'K': setdepth() ; break;
case 'I': initialize() ; break;
case 'L': loaddata() ; break;
case 'M': menu_sw = toggle(menu_sw) ; break;
case 'O': oride_sw = toggle(oride_sw) ; break;
case 'P': hardcopy() ; break;
case 'R': setrev() ; break;
case 'S': presave() ; break;
case 'T': think() ; break;
case 'V': view() ;
}
}
setassump()
{ int qa1, qa2; char dumment[2];
qa1 = MAX - 3;
printf("\nWhat is the maximum number of assumptions to allow?");
printf("\nAbsolute maximum is %d, absolute minimum is zero.",qa1);
printf("\nYour choice: ");
scanf("%d",&qa2); gets(dumment);
if (qa2 < 0)
assumpno = 0;
else
{ if (qa2 > qa1)
assumpno = qa1;
else
assumpno = qa2; }
}
setdepth()
{ int sd1, sd2; char dumment[2];
sd1 = MAX - 1;
printf("\nHow many levels shall be examined in thinking?");
printf("\nAbsolute maximum is %d, absolute minimum is 3.",sd1);
printf("\nYour choice: ");
scanf("%d",&sd2); gets(dumment);
if (sd2 < 3)
srchdpth = 3;
else
{ if (sd2 > sd1)
srchdpth = sd1;
else
srchdpth = sd2;}
}
initialize()
{ int sx1; char empstr[] = "@@@@@";
printf("\n\nInitializing storage.");
for (sx1 = 0; sx1 < MAX; sx1++)
{ blank1pt(sx1);
strcpy(subjs[sx1],empstr); }
}
setfwd()
{ ff1 = dfwd;
dflt("forward");
dfwd = ff1;
}
setrev()
{ ff1 = drev;
dflt("reverse");
drev = ff1;
}
toggle(cv)
char *cv;
{ if (cv == 'Y')
return('N');
else
return('Y');
}
dflt(st1)
char *st1[ ];
{ float ff2; char tx;
printf("\n\nEnter new default %s percentage",st1);
printf("\n 100 = certainty, 0 = never, must be at least zero. ");
scanf("%f",&ff2); tx = getchar();
if (ff2 < 0 || ff2 > 100)
{ printf("\nInvalid entry."); marktime(); }
else
ff1 = ff2;
}
disphelp(tt)
char *tt[ ];
{ int wk2; char tc; FILE *infile;
infile = NULL;
tc = "C";
while (infile == NULL && tc != 'A' && tc != 'a')
{ if (filestat == 0)
{ printf("\n\n Insert disk containing ART-CEE help files.");
printf("\n Press 'A' to abort, any other key to proceed.");
tc = getchar(); }
if (toupper(tc) != 'A')
{ infile = fopen(tt,"r");
filestat = infile; } }
if (toupper(tc) != 'A' && infile != NULL);
{ wk2 = 0; system("cls");
while (fgets(filebuf ,81,infile) != NULL)
{ if (wk2 > 20)
{ marktime(); system("cls"); wk2 = 0; }
printf("%s",filebuf );
wk2++; }
fclose(infile); }
}
help()
{ char tcc[2];
disphelp("help1.aih");
gets(tcc);
while(tcc [0] == 'R' || tcc [0] == 'C' || tcc [0] == 'r' ||
tcc [0] == 'c' || tcc [0] == 'Q' || tcc [0] == 'q')
{ if (tcc [0] == 'R' || tcc [0] == 'r')
disphelp("help2.aih");
else
{ if (tcc[0] == 'C' || tcc [0] == 'c')
disphelp("help4.aih");
else
disphelp("help3.aih"); }
printf("\n\n Press 'R' for rules, 'Q' for queries, 'C' for commands,");
printf("\n anything else to return to main input. ");
gets(tcc);}
}
failfile()
{ printf("\n\nFile procedure has failed."); marktime();
}
exec_string()
{ char pred[77]; int rs1, rs2, rs3, rs4, findsub();
rs4 = 1;